package com.example.seckill.repository;

import com.example.seckill.entity.Seckill;
import org.apache.ibatis.annotations.Update;
import org.hibernate.annotations.SQLUpdate;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDateTime;
import java.util.Date;

public interface SeckillRepository extends JpaRepository<Seckill, Long> {

    /**
     * 减库存
     * @param seckillId
     * @param killTime
     * @return
     */
    @Modifying
    @Query("update Seckill set stock = stock - 1 where stock > 0 and id=?1 and startTime <= ?2 and endTime >= ?2")
    int reduceStock(long seckillId, Date killTime);


}
